package com.wxmit.base.exception.excel;

import com.wxmit.base.exception.BaseException;
import com.wxmit.base.util.StringUtils;
import lombok.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * excel 导入模版 读取数据 校验异常
 *
 * @author huangxiong
 * @version V1.0
 * @date 2023/1/6 15:27
 */
@Getter
public class ExcelReadValidException extends BaseException {
    private static final long serialVersionUID = 1L;

    private List<ValidError> list;

    private final Integer code = 500;
    private final String message = "Excel Read Validate Is Exception";

    @Override
    public String toString() {
        return "ExcelReadValidException{" +
                "code=" + code +
                ",message=" + message +
                ",list=" + list +
                '}';
    }

    public void putValidError(ValidError validError){
        if(Objects.isNull(list)){
            list = new ArrayList<>();
        }
        list.add(validError);
    }


    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class ValidError{
        private Integer rowNum;
        private Integer cellNum;
        private String  message;

        @Override
        public String toString(){
            return Objects.isNull(cellNum)?
                    StringUtils.format("第{}行，抛出异常：{}",rowNum ,message)
                    :
                    StringUtils.format("第{}行，第{}列，抛出异常：{}",rowNum,cellNum,message);
        }
    }

}
